﻿Imports DotNetNuke.Entities.Tabs
Imports Aricie.DNN.Services

Namespace Aricie.DNN.Modules.LuceneSearch.Business
    Public Class LuceneContext
        Private Shared lock As New Object
        Private _CurrentTabs As Dictionary(Of Integer, TabInfo)

        Public Shared ReadOnly Property Instance() As LuceneContext
            Get
                Dim context As HttpContext = HttpContext.Current
                If context IsNot Nothing Then
                    If context.Items("LuceneContext") Is Nothing Then
                        SyncLock lock
                            If context.Items("LuceneContext") Is Nothing Then
                                context.Items("LuceneContext") = New LuceneContext
                            End If
                        End SyncLock
                    End If
                    Return DirectCast(context.Items("LuceneContext"), LuceneContext)
                End If
                Return New LuceneContext
            End Get
        End Property

        Public ReadOnly Property CurrentTabs() As Dictionary(Of Integer, TabInfo)
            Get
                If _CurrentTabs Is Nothing Then
                    If PortalSettings IsNot Nothing Then
                        _CurrentTabs = New Dictionary(Of Integer, TabInfo)
                        For Each objTab As TabInfo In PortalSettings.DesktopTabs
                            _CurrentTabs(objTab.TabID) = objTab
                        Next
                    Else
                        Return New Dictionary(Of Integer, TabInfo)
                    End If
                End If
                Return _CurrentTabs
            End Get
        End Property
    End Class
End Namespace
